/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.cotec.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author magalhaes
 */
@Entity
@Table(name = "equipamento")
@NamedQueries({@NamedQuery(name = "Equipamento.findAll", query = "SELECT e FROM Equipamento e"), 
			   @NamedQuery(name = "Equipamento.findById", query = "SELECT e FROM Equipamento e WHERE e.id = :id"), 
			   @NamedQuery(name = "Equipamento.findByCodigo", query = "SELECT e FROM Equipamento e WHERE e.codigo = :codigo"), 
			   @NamedQuery(name = "Equipamento.findByNomeEquipamento", query = "SELECT e FROM Equipamento e WHERE e.nomeEquipamento = :nome")})
public class Equipamento implements Serializable {
    private static final long serialVersionUID = 1L;
    
    public static String TIPO_EQUIPAMENTO = "E";
    public static String TIPO_PERIFERICO = "P";
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "codigo", length=45)
    private String codigo;
    @JoinColumn(name = "nomeEquipamento", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private NomePeriferico nomeEquipamento;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "equipamento")
    private List<Inbox> inboxList;
    @OneToOne(mappedBy = "equipamento")
    private Posicao posicao;
    
    public Equipamento() {
    	this.setNomeEquipamento(new NomePeriferico());
    }

    public Equipamento(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public List<Inbox> getInboxList() {
        return inboxList;
    }

    public void setInboxList(List<Inbox> inboxList) {
        this.inboxList = inboxList;
    }

    public Posicao getPosicao() {
        return posicao;
    }

    public void setPosicao(Posicao posicao) {
        this.posicao = posicao;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    public NomePeriferico getNomeEquipamento() {
		return nomeEquipamento;
	}

	public void setNomeEquipamento(NomePeriferico nomeEquipamento) {
		this.nomeEquipamento = nomeEquipamento;
	}

	@Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Equipamento)) {
            return false;
        }
        Equipamento other = (Equipamento) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.cotec.model.Equipamento[id=" + id + "]";
    }

}
